/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						script_specific_hero_boolean_expression.cpp

	$Header: /heroes4/script_specific_hero_boolean_expression.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "script_specific_hero_boolean_expression.h"

#include "adventure_map.h"
#include "hero.h"
#include "script_targeting.h"
#include "streambuf_operators.h"

// --------------------------------------------------------------------------
// t_script_specific_hero_boolean_expression members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_specific_hero_boolean_expression::read(std::streambuf& stream, int version )
{
	if (!t_abstract_script_boolean_expression::read( stream, version) )
		return false;

	return read_string16( stream, m_hero_name );
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_specific_hero_boolean_expression::read_from_map(
	std::streambuf &	stream,
	int					format_version )
{
	return read_string16( stream, m_hero_name ) && !m_hero_name.empty();
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_specific_hero_boolean_expression::write( std::streambuf &	stream ) const
{
	if (!t_abstract_script_boolean_expression::write( stream ))
		return false;

	return write_string16( stream, m_hero_name );
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
t_script_specific_hero_boolean_expression::t_result 
t_script_specific_hero_boolean_expression::evaluate(t_expression_context_hero const& context) const
{
	assert(context.map);
	t_hero const* hero = context.map->get_mapped_hero( m_hero_name );
	return do_evaluate(hero);
}

t_script_specific_hero_boolean_expression::t_result 
t_script_specific_hero_boolean_expression::evaluate(t_expression_context_town const& context) const
{
	assert(context.map);
	t_hero const* hero = context.map->get_mapped_hero( m_hero_name );
	return do_evaluate(hero);
}

t_script_specific_hero_boolean_expression::t_result 
t_script_specific_hero_boolean_expression::evaluate(t_expression_context_object const& context) const
{
	assert(context.map);
	t_hero const* hero = context.map->get_mapped_hero( m_hero_name );
	return do_evaluate(hero);
}

t_script_specific_hero_boolean_expression::t_result 
t_script_specific_hero_boolean_expression::evaluate(t_expression_context_army const& context) const
{
	assert(context.map);
	t_hero const* hero = context.map->get_mapped_hero( m_hero_name );
	return do_evaluate(hero);
}

t_script_specific_hero_boolean_expression::t_result 
t_script_specific_hero_boolean_expression::evaluate(t_expression_context_global const& context) const
{
	assert(context.map);
	t_hero const* hero = context.map->get_mapped_hero( m_hero_name );
	return do_evaluate(hero);
}


// --------------------------------------------------------------------------
// t_script_hero_is_dead members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
t_script_hero_is_dead::t_result
t_script_hero_is_dead::do_evaluate( t_hero const* hero ) const
{
	return hero ? hero->is_dead() : false;
}

// --------------------------------------------------------------------------
// t_script_hero_is_imprisoned members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
t_script_hero_is_imprisoned::t_result
t_script_hero_is_imprisoned::do_evaluate( t_hero const* hero ) const
{
	return hero ? hero->is_imprisoned() : false;
}
